const helper = require('./helper')
module.exports = {
    /** rpx 转px */
    rpx2px(rpx) {
        const screenWidth = tt.getSystemInfoSync().screenWidth
        return (screenWidth * Number.parseInt(rpx)) / 750;
    },
    getDistance(startPos, endPos) {
        return Math.hypot(endPos.x - startPos.x, endPos.y - startPos.y);
    },
    // 获取min到max之间随机数
    getRandom(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    },
    //是否全屏
    isFullScreen() {
        const hasFull = tt.getSystemInfoSync().screenRatio === 1;
        return hasFull;
    },
    async getOpenIdOrCode() {
        const openId = tt.getStorageSync('openId');
        if (openId) {
            return { openId }
        } else {
            const { anonymousCode, code } = await helper.ttLogin()
            return { anonymousCode, code }
        }
    }
}